package com.csii.activiti.server.core.listener;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.csii.activiti.server.core.entity.ActFlowData;
import com.csii.activiti.server.core.entity.ActFlowNode;
import com.csii.activiti.server.core.listener.base.BaseServiceNodeExecutor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@Slf4j
public class AdvancedServiceNodeExecutor extends BaseServiceNodeExecutor {

    private String customDataKey = "serviceUrl";

    @Override
    public String serviceNodeDescription() {
        return "高级模式";
    }

    @Override
    public boolean isShowList() {
        return false;
    }


    @Override
    public void executeService(ActFlowNode actFlowNode, Map<String, Object> customData, Map<String, Object> formData, ActFlowData flowData) {
        String serviceUrl = (String) customData.get(customDataKey);
        try {
            String result = HttpUtil.post(serviceUrl, JSONObject.toJSONString(formData));
            log.info("advancedServiceNodeExecute result is : {}",result);
        }catch (Exception e){
            log.info("advancedServiceNodeExecute is error : {}",e);
        }
    }
}
